<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/25 0025
 * Time: 10:56
 */

namespace app\wap\controller;
use think\Db;
use Yansongda\Pay\Pay;
class Pays extends Middle
{

    //todo 支付宝
    protected static $alipay = [
        'app_id'            => '2019062065611567',     //todo appid
        'notify_url'        => 'http://www.aibinance.com/public/index.php/zfbreturn',
        'ali_public_key'    => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzBu++i8EwQf1DyXMboiRGqs78tuxlDOQTNJWGf1TvPavpLDwfI0oNkChIccBWzxrIsVFlQBxnI5az8sMKcY3YhEqiPcPTwdeqoooDNqSXJY6pR+7upqx5Gvo8X0JHx7cx4b0jhHz7dbERk8+kXTpLePw+RmUMkHiTNUDCfExU1y4bMrdzL7E8MzfH7yM+w35iSX2cmRt3Y7/NAOctQZXMl03QOTExUjGINejnDSygPb0JFkcMphtR8FnjdKWVbTeEpKDuonjafdewXK3vhdPtBp3bWfG8vfQeIYPA1/GuUBjOKdYzlYCXWFtjqC15dDEz158Xjfjmd00mBWcj1hWVwIDAQAB',
        'private_key'       => 'MIIEowIBAAKCAQEA68p/STKYwVMELyTYo8WuNDHjYTVRJOpcDmwiVyST/NfY30/Be2srGFtYHJyBzP8o6emLkwGFCBjx/SB/SQ8xpdb3H6KRqF9J39Su8TI8ae9qbQIZ12ijRL1L+JdhOQy3DlzXkXeDJMynyoiSEa+SiAO8AQM2+/Xw3fkjeybCAu79BZhVXZFGMN+v2D1Conyw/vI3N0G5V/BZFXPG3FDZc+iIVrT+Qe18ZWihZFNsn2nkmRrZJcJLPoxC8irblKgVUUxN+pMi/tGFlZm7NNwJPK/t+tUExFaQhJ1Y3oBfW460kiUcKN5tCl/DjEa5HOqE7CxhvTBhsxm41S0EtdRbLwIDAQABAoIBAG+TbxAQJUC2K/CzGuDEll6UjOhe9nrle5JHkShzYqPu7+0cLI5edBIeh19in/mFdLLblPSHb5AZXclOK21DB1dWlbIel5Z5INgOKIpy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Lkg0IC9UNaM9bQ5hR5Nn8'];


    //todo 微信
    protected static $wechat = [
        'appid'             => 'wxb598cf50e9fdcb41', // APP APPID
        'mch_id'            => '1541729541',
        'key'               => 'Albinance1ba59abbe56e057f20f883e',
        'notify_url'        => 'http://www.aibinance.com/public/index.php/payback/wechat',
    ];


    /**
     * Created by xiaosong
     * E-mail:306027376@qq.com
     * 支付签名获取
     */
    public function paySign()
    {

        $gmap = ['id'=>$this->data['id'],'type'=>1];
        $gear = Db::name('gear')->where($gmap)->find();
        if(!$gear)return $this->returnError('档位信息错误');
        $oset = [
            'time'  =>time(),
            'number'=>'AL'.time().rand(10000,99999),
            'id'    =>$gear['id'],
            'status'=>0,
            'uid'   =>$this->uid,
          	'way'	=>$this->data['PayWay'],
        ];
        $oid = Db::name('order')->insertGetId($oset);
        if(!$oid)return $this->returnError('系统忙');
        switch ($this->data['PayWay']){
            case 'alipay'://支付宝支付
                $order = [
                    'out_trade_no' => $oset['number'],
                    'total_amount' => $gear['price'], //单位元
                  	//'total_amount' => '0.01', //单位元
                    'subject' => '订阅服务',
                    'body' =>  $oid,//自定义参数

                ];
                $sign = Pay::alipay(self::$alipay)->app($order)->getContent();
                break;
            case 'wechat': //微信支付
                $order = [
                    'out_trade_no' => $oset['number'],
                    'body' => '订阅服务',
                    'total_fee' => $gear['price']*100,
                  	//'total_fee' => '1',
                    'attach'=> $oid,
                ];

                $json = Pay::wechat(self::$wechat)->app($order)->getContent();
                $sign = json_decode($json,true);
                break;
            default:
                return $this->returnError('支付类型错误');
                break;
        }
        return $this->returnSuccess($sign);
    }



}